<html>
<head>
<title>Option</title>
<link href="../styles.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../jquery-1.7.1.min.js"></script>.
<script type="text/javascript" src="../jquery.dualListBox-1.3.js"></script>
<script type="text/javascript" src="../const.js"></script>
<script type="text/javascript">
(function($){
	
	var tv_series = [];
	var test_url;
	var new_url;
	var s="";
	
	$.get(TVSHOWS_URL,function(data){
		$('a[href*=".htm"]',data).each(function(){
			test_url = $(this).attr('href');
			var option = $('<option />');
			option.attr('value',((test_url).search(BASE_URL) < 0) ? BASE_URL+test_url : test_url).text($(this).text());
			$('#box1View').append(option);
			
		});
		
		$.configureBoxes({transferMode: 'copy'});
			
		if(typeof localStorage["subscribeds"] !== "undefined" && localStorage["subscribeds"] !== ""){
			s =localStorage["subscribeds"]
			var parsed_s = $.unique(s.split(","));
			$.each(parsed_s,function(i){
				$('option[value="' + parsed_s[i] + '"]').clone().appendTo('#box2View').end().end();
				$('option[value="' + parsed_s[i] + '"]').addClass('copiedOption');
			})
		}
		
		/*
		$("#combobox").change(function(){
			$.get($("#combobox option:selected").attr('value'),function(data){
				$("#combobox1").remove();
				$("#combobox2").remove();
				$("#combobox").after("<select id='combobox1'><select>");
				$('a[href*=".htm"]',data).each(function(){
					console.log($(this).attr('href'));
					test_url = $(this).attr('href');
					var option = $('<option />');
					option.attr('value',((test_url).search(BASE_URL) < 0) ? BASE_URL+test_url : test_url).text($(this).text());
					$('#combobox1').append(option);
				});
				$("#combobox1 option:last").attr('selected',true);
			
				$("#combobox1").change(function(){
					$.get($("#combobox1 option:selected").attr('value'),function(data){
						$("#combobox2").remove();
						if(typeof($('a[href*=".htm"]',data))!==undefined){
							$("#combobox1").after("<select id='combobox2'><select>");
							$('a[href*=".htm"]',data).each(function(){
								console.log($(this).attr('href'));
								test_url = $(this).attr('href');
								var option = $('<option />');
								option.attr('value',((test_url).search(BASE_URL) < 0) ? BASE_URL+test_url : test_url).text($(this).text());
								$('#combobox2').append(option);
							});
							$("#combobox2 option:last").attr('selected',true);
						}
					});
				});
			});
		});
		*/
		$("#getLatestEp").click(function(){
			console.log("y");
			$('#box2View option').each(function(){
				var series_name = $(this).text();
				$.get($(this).attr('value'),function(data){
					var url = BASE_URL + $('a[href*=".htm"]',data).last().attr('href');
					console.log(url);
					$.get(url,function(data2){
						console.log('v');
						console.log($('a[href*=".htm"]',data2).last().text());
						
					});
					
				});
			});
		});
	});
	
	
	
	
		
})(jQuery);
</script>
</head>

<body>
<button id="getLatestEp">Get Latest Ep</button>
<table>
	<tr>
		<td>
			Filter: <input type="text" id="box1Filter" /><button type="button" id="box1Clear">X</button><br />
			<select id="box1View" multiple="multiple" style="height:500px;width:300px;"></select><br/>
			<span id="box1Counter" class="countLabel"></span>
		    <select id="box1Storage"></select>
		</td>

        <td>
			<button id="to2" type="button">&nbsp;>&nbsp;</button>
			<button id="allTo1" type="button">&nbsp;<<&nbsp;</button>
			<button id="to1" type="button">&nbsp;<&nbsp;</button>
		</td>

		<td>
			Filter: <input type="text" id="box2Filter" /><button type="button" id="box2Clear">X</button><br />
			<select id="box2View" multiple="multiple" style="height:500px;width:300px;"></select><br/>
			<select id="box2Storage"></select>
		</td>
	</tr>
</table>


</body>

</html>